<?php

use App\Models\Cts;
use App\Models\Rural;
use App\Models\Scene;
use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});
Route::group(['prefix' => 'mobile'], function () {
    Route::group(['prefix' => 'flow'], function () {
        Route::post('/', 'MobileController@flow');
        Route::get('/scenes', 'MobileController@scenes');
    });
    Route::group(['prefix' => 'analysis'], function () {
        Route::get('/sceneAnalysis', 'MobileController@sceneAnalysis');
        Route::get('/ctsAnalysis', 'MobileController@ctsAnalysis');
    });

});
Route::group(['prefix' => 'auth'], function () {
    Route::post('login', 'AuthController@login');

    Route::middleware('token.check')->group(function () {
        Route::post('refresh', 'AuthController@refresh');
        Route::post('user', 'AuthController@user');
        Route::post('logout', 'AuthController@logout');
        Route::post('checkToken', 'AuthController@checkToken');
    });
});
Route::group(['prefix' => 'index'], function () {
    Route::post('/', 'IndexController@index');
    Route::any('/area', 'IndexController@area');
    Route::get('/scene', 'IndexController@scene');
    Route::get('/integrity', 'IndexController@integrity');
    Route::get('/operation', 'IndexController@operation');
    Route::get('/flows', 'IndexController@flows');
    Route::get('/notice/{type?}/{module?}', 'IndexController@notice');
});
Route::group(['prefix' => 'flow'], function () {
    //客流2级
    Route::any('/index/{scene_id?}', 'FlowController@index');
    Route::any('/flow', 'FlowController@flow');
    //客流来源
    Route::any('/source/{scene_id?}', 'FlowController@source');
    Route::any('/getSourceRate', 'FlowController@getSourceRate');
    //客流驻留分析
    Route::any('/stay/{scene_id?}/{date?}', 'FlowController@stay');
    Route::any('/slot/{scene_id?}', 'FlowController@slot');
    Route::any('/sceneAvgStay', 'FlowController@sceneAvgStay');
    //假日客流
    Route::any('/holiday', 'FlowController@holiday');
    Route::any('/holidayFlow/{type?}', 'FlowController@holidayFlow');//假日客流分析
    Route::any('/holidaySceneFlow/{type?}', 'FlowController@holidaySceneFlow');//假日热门景区分析
    Route::any('/topFive/{type?}', 'FlowController@topFive');//假日热门景区分析
    Route::any('/overYearHolidayFlow', 'FlowController@overYearHolidayFlow');//历年假日客流统计
    Route::any('/topThree', 'FlowController@topThree');//假日客流TOP3


    //客流量分析
    Route::any('/sceneFlowByDate/{date?}', 'FlowController@sceneFlowByDate');//景区客流量分析
    Route::any('/areaFlowByDate/{date?}', 'FlowController@areaFlowByDate');//各区县客流监测对比分析
    Route::any('/dataSourceRate/{scene_id?}', 'FlowController@dataSourceRate');//客流数据统计分析 参数{start,end}
    Route::any('/flowType/{scene_id?}', 'FlowController@flowType');//客流量类型统计 参数{start,end}
    Route::any('/line', 'FlowController@line');//客流量类型统计
    Route::any('/sightseeingWay/{scene_id?}', 'FlowController@sightseeingWay');//游览方式分析  参数{start,end}
});
Route::group(['prefix' => 'sincerity'], function () {
    //诚信2级
    Route::any('/', 'SincerityController@index');
    Route::any('/complain', 'SincerityController@complain');
    Route::any('/rb/{type?}/{take?}', 'SincerityController@rb');//红黑榜 参数{area_id}
    Route::any('/search', 'SincerityController@ctsSearch');
    Route::any('/creditAnalysis', 'SincerityController@creditAnalysis');//旅行社信用分析
    Route::any('/guideAnalysis/{limit?}', 'SincerityController@guideAnalysis');//导游信用分析
    Route::any('/getAll/{year?}', 'SincerityController@getAll');//旅游商户信用分析

    //诚信3级 诚信系统1
    Route::post('/merchantInfo', 'SincerityController@merchantInfo');//旅游商户信息查询 method:post:参数{type,area_id,search}
    Route::post('/complaintInfo', 'SincerityController@complaintInfo');//旅游纠纷信息查询 method:post:参数{type,target,status,search}

    //诚信3级 诚信系统2
    Route::post('/notice', 'SincerityController@notice');//旅游商户信息查询 method:post:参数{area_id}
    Route::post('/negativeCtsTop10', 'SincerityController@negativeCtsTop10');//差评旅行社TOP10 method:post:参数{area_id}
    Route::post('/negativeCtsProduct', 'SincerityController@negativeCtsProduct');//旅行社差评产品预警

});
Route::group(['prefix' => 'monitor'], function () {
    Route::any('/', 'MonitorController@index');
    Route::any('/alarm/{title?}', 'MonitorController@alarm');
    Route::any('/monitor', 'MonitorController@monitor');
    Route::any('/getAlarm', 'MonitorController@getAlarm');
});
Route::group(['prefix' => 'operation'], function () {
    Route::any('/', 'OperationController@index');
    //2级
    Route::any('/baseData', 'OperationController@baseData');
    Route::any('/ctsHotLine', 'OperationController@ctsHotLine');
    Route::any('/teamNumTrend', 'OperationController@teamNumTrend');
    Route::any('/merchantContrast', 'OperationController@merchantContrast');
    Route::any('/sceneResources', 'OperationController@sceneResources');

    //3级
    Route::any('/sceneCategory', 'OperationController@sceneCategory');
    Route::any('/mapPoint/{scene_id?}', 'OperationController@mapPoint');//景点基础数据标注 参数{type}
    //景区运行监测 page1
    Route::any('/typeRate', 'OperationController@typeRate');//旅游产业基础运营数据
    Route::any('/spots', 'OperationController@spots');//景区景点
    Route::any('/cts', 'OperationController@cts');//旅行社
    //景区运行监测 page2
    Route::any('/hotel', 'OperationController@hotel');//旅行社
    Route::any('/restaurant', 'OperationController@restaurant');//餐饮
    Route::any('/guides', 'OperationController@guides');//导游
    Route::any('/cars', 'OperationController@cars');//车辆
    Route::any('/merchant', 'OperationController@merchant');//商户入驻
    Route::any('/shoppingMall', 'OperationController@shoppingMall');//旅游商城
    Route::any('/gdp', 'OperationController@gdp');//gdp
    //景区舆情监测
    Route::any('/complaint', 'OperationController@complaint');//旅游投诉
    Route::any('/complaintQuestion', 'OperationController@complaintQuestion');//投诉问题列表 可选参数{start,end}
    Route::any('/dynamic', 'OperationController@dynamic');//互联网旅游话题舆情动态
    Route::any('/get_dynamic_point', 'OperationController@get_dynamic_point');//
    Route::any('/set_dynamic_point', 'OperationController@set_dynamic_point');
});
Route::group(['prefix' => 'gps'], function () {
    Route::any('/', 'GpsController@index');
    Route::any('/history', 'GpsController@history');
});
Route::any('/area', function () {
    return \App\Models\Area::pluck('title', 'id');
});
Route::get('/sceneList', 'IndexController@sceneList');
//Route::any('/target_id',function (Request $request){
//    $q=$request->get('q');
//    $data = [];
//
//    if($q==0){
//        $data = Scene::all()->pluck('title','id');
//    }elseif ($q==1){
//        $data = Cts::all()->pluck('title','id');
//    }elseif ($q==2){
//        $data = Rural::all()->pluck('title','id');
//    }elseif ($q==3){
//        $data = \App\Models\Guide::all()->pluck('name','id');
//    }
//    $data[0]='若无选此项';
//    return response()->json($data);
//});

Route::group(['prefix' => 'v1'], function () {
    Route::group(['prefix' => 'basic'], function () {
        Route::get('/getScenes', 'ApiController@getScenes');//景区基础数据 参数 {keyword?}
        Route::get('/getHotel', 'ApiController@getHotel');//酒店基础数据 参数 {keyword?}
        Route::get('/getCTS', 'ApiController@getCTS');//旅行社基础数据 参数 {keyword?}
        Route::get('/getTeams', 'ApiController@getTeams');//团队基础数据  参数 {keyword?,date?}
        Route::get('/getGuides', 'ApiController@getGuides');//导游基础数据  参数 {keyword?}
        Route::get('/getCars', 'ApiController@getCars');//导游基础数据  参数 {keyword?}
        Route::get('/getSceneMerchant', 'ApiController@getSceneMerchant');//商户基础数据
    });
    Route::group(['prefix' => 'gps'], function () {
        Route::get('/', 'ApiController@gps');//gps
    });
    Route::group(['prefix' => 'waterWorld'], function () {
        Route::get('/flows', 'ApiController@waterWorldFlows');//客流统计分析 参数 {keyword?}
        Route::get('/operation', 'ApiController@waterWorldOperation');//产业运营
    });
    Route::group(['prefix' => 'peachGarden'], function () {
        Route::get('/flows', 'ApiController@peachGardenFlows');//客流统计分析 参数 {keyword?}
        Route::get('/operation', 'ApiController@peachGardenOperation');//产业运营
    });

    Route::any('/release', 'ApiController@release');//产业运营
});

Route::any('/target_id', function (Request $request) {
    $q = $request->get('q');
    $text = $q == 'guides' ? 'name' : 'title';
    if ($q == 'guides')
        $data = DB::table($q)->get(['id', DB::raw($text . ' as text')]);
    else
        $data = DB::table($q)->get(['id', DB::raw($text . ' as text')]);
    return response()->json($data);
});
Route::any('/sightseeingWay/date', function (Request $request) {
    $q = $request->get('q');
    $data = DB::table('flows')->where([['time', 0], ['scene_id', $q]])->get([DB::raw('date as id'), DB::raw('date as text')]);
    return response()->json($data);
});
Route::group(['prefix' => 'manager'], function () {
    Route::any('/department', function (Request $request){
        $id = $request->get('q');
        $data = \App\Models\Department::where('mechanism_id',$id)->get(['id', DB::raw('title as text')]);//DB::raw('id as id')
        return response()->json($data);
    });
    Route::any('/post', function (Request $request){
        $id = $request->get('q');
        $data = \App\Models\Post::where('department_id',(int)$id)->get(['id',DB::raw('title as text')]);
        return response()->json($data->toArray());
    });
});
Route::post('/test', 'ApiController@get_dh_list');

